$("#deleteChuanghuxinxi").click(function(){
	$(this).closet('$("form")').remove();
});
/*点击添加风格*/
$(".toAdd").hide();
$(".addBtn").click(function(){
	$(".addButton input").show();
	$(".toAdd").show();
})
$(".toAdd").click(function(){
		var styleVal = $(".addButton input").val();
		if(styleVal == ""){
		    alert("请输入文字");
		}else{
			$.post('http://192.168.0.90:8080/bukeManage/shoppingmall/addStyle.do',{'styleContent':styleVal},function(data){
				console.log(styleVal);
			    console.log(data);
				var inpEle = '<label class="checkbox-inline"><input type="checkbox" value="'+data+'">'+styleVal+'</label>';
				console.log(inpEle);
				$("#fengge").append(inpEle);
				$(".addButton input").val("");
				$(".addButton input").hide();
				$(".toAdd").hide();
			})
		}		
	})
$(".toAdd1").hide();
$(".addBtn1").click(function(){
	$(".addButton1 input").show();
	$(".toAdd1").show();
	
})
$(".toAdd1").click(function(){
		var styleVal1 = $(".addButton1 input").val();
		if(styleVal1 == ""){
			alert("请输入文字");
		}else{
			$.post('http://192.168.0.90:8080/bukeManage/shoppingmall/addLocation.do',{'locationContent':styleVal1},function(data){
				//console.log(styleVal1);
			    var inpEle = '<label class="checkbox-inline"><input type="checkbox" value="'+data+'">'+styleVal1+'</label>';
				$("#changjing").append(inpEle);
				$(".addButton1 input").val("");
				$(".addButton1 input").hide();
				$(".toAdd1").hide();
			})
		}		
	})

	
	/*点击保存*/
	/*$(".save").click(function(){
		console.log("222");
		$.post("http://192.168.0.90:8080/bukeManage/shoppingmall/toUpdateGoods.do"，{sampleId:thisRequest.sampleId},function(data){
			console.log(data);
		})
	})*/
	
	/*上传商品型号查询重复*/
	$("#serialnumber").blur(function(){
		var numInp = $("#serialnumber").val();
		$.post("http://192.168.0.90:8080/bukeManage/shoppingmall/select_serialnumber.do",{"serialnumber":numInp},function(numberData){
			console.log(typeof(numberData));
			var numberData = JSON.parse(numberData);
			if(numberData == "1"){
				alert("您输入的型号已存在，请重新输入");
			}
		})
	})
	/*成品帘*/
	$("#serialnumber1").blur(function(){
		console.log("222");
		var numInp = $("#serialnumber1").val();
		$.post("http://192.168.0.90:8080/bukeManage/shoppingmall/select_serialnumber.do",{"serialnumber":numInp},function(numberData){
			//console.log(typeof(numberData));
			var numberData = JSON.parse(numberData);
			if(numberData == "1"){
				alert("您输入的型号已存在，请重新输入");
			}
		})
	})
	
	//配件
	$("#serialnumber2").blur(function(){
		var numInp = $("#serialnumber2").val();
		$.post("http://192.168.0.90:8080/bukeManage/shoppingmall/select_serialnumber.do",{"serialnumber":numInp},function(numberData){
			console.log(typeof(numberData));
			var numberData = JSON.parse(numberData);
			if(numberData == "1"){
				alert("您输入的型号已存在，请重新输入");
			}
		})
	})
	
	
	
	
//上传布艺帘商品
$("#buYiLianNext").click(function(){
	var styleIds = "";
	var r = $("#fengge input:checked");
	for(var a=0;a<r.length;a++){
		if(a==0){
			styleIds+="[";
		}
		if(a<r.length-1){
			styleIds+=r[a].value+",";
		}
		if(a==r.length-1){
			styleIds+=r[a].value+"]";
		}
//		else if(a==r.length-1){
//			styleIds+=r[a].value+"]";
//		}else{
//			styleIds+=r[a].value+",";
//		}
	}
	var locationIds = "";
	var l = $("#changjing input:checked");
	for(var a=0;a<l.length;a++){
		if(a==0){
			locationIds+="[";
		}
		if(a<l.length-1){
			locationIds+=l[a].value+",";
		}
		if(a==l.length-1){
			locationIds+=l[a].value+"]";
		}
		/*else if(a==r.length-1){
			locationIds+=l[a].value+"]";
		}else{
			locationIds+=l[a].value+",";
		}*/
	}
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil form");
	//console.log(form);
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
		console.log(str);
		console.log(compositions);
	}
		
	var sampleImg = $("#sampleImg>img").attr("src");
	//console.log(sampleImg);
	var makeImg = $("#makeImg>img").attr("src");
	//console.log(makeImg);
	var str1 = $("#sampleT").serialize();
	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	var imgs = {};
	imgs.mainImg = sampleImg;
	
	imgs.makeImg = makeImg;
	imgs.assistImg = detailsImg;
	console.log(imgs);
	str1=decodeURIComponent(str1,true);
	str2 ="styleIds="+styleIds+"&locationIds="+locationIds;
	str2 = updateString(str2);
	
	str1 = updateString(str1);
	console.log(JSON.stringify(imgs));
	/*表单提交*/
	var validator = $("#sampleT").validate({
        rules : {
            // 对应表单元素的name属性
        	"style":{required:true},
            "version" : {required:true,number:true},
            "isSty" : {required:true},
            "structore" : {required:true},
            "brand" : {required:true},
            "priceHz" : {required:true,number:true},
            "priceDk" : {required:true,number:true},
            "priceSHz" : {required:true,number:true},
            "descript" : {required:true},
            "wash" : {required:true},
            "locationId" : {required:true},
            "structure" : {required:true},
            "spur" : {required:true},
            "timeFold" : {required:true},
            "sampleType" : {required:true},
            "optionalType" : {required:true},
            "clothList" : {required:true},
            "kinds" : {required:true},
            "shading" : {required:true},
            "color" : {required:true},
            "mainCloth" : {required:true},
            "setSize" : {required:true},
            "styleId" : {required:true},
            "breadthStatus" : {required:true},
            "series" : {required:true,number:true},
            "holePeice" : {required:true,number:true},
            "zhePrice" : {required:true,number:true},
        },
        messages : {
        	"isSty":{required:'请选择图片款式'},
        	"isSty":{required:'请选择风格'},
        	"holePeice" : {required:"请输入打孔价格"},
            "zhePrice" : {required:"请输入韩褶价格"},
        	"series":{required:'请输入系列号'},
        	"structore":{required:'请选择结构'},
            "version" : {required:'请输入型号'},
            "brand" : {required:'请输入品牌'},
            "priceHz" : {required:'请输入价格'},
            "priceDk" : {required:'请输入价格'},
            "priceSHz" : {required:'请输入价格'},
            "wash" : {required:'请输入洗涤说明'},
            "locationId" : {required:'请选择场景'},
            "structure" : {required:'请选择结构'},
            "spur" : {required:'请选择花距'},
            "timeFold" : {required:'请选择倍褶'},
            "sampleType" : {required:'请选择样品类型'},
            "optionalType" : {required:'请选择可选类型'},
            "clothList" : {required:'请选择材质'},
            "kinds" : {required:'请选择材质'},
            "shading" : {required:'请选择遮光率'},
            "color" : {required:'请选择颜色'},
            "mainCloth" : {required:'请选择材质'},
            "setSize" : {required:'请选择尺寸'},
            "breadthStatus" : {required:'请选择定宽/定高'},
            "styleId" : {required:'请选择风格'},
            "descript" : {required:'请输入描述'},
            "price" : {required:'请输入价格'},
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     
     if($("#addGoodsDeatil form").serialize()){
    	 $.post(
 				"http://192.168.0.90:8080/bukeManage/shoppingmall/updategoodsubmit.do",
 				{
 					sample:str1,
 					properties:str2,
 					compositions:JSON.stringify(compositions),
 					imgs:JSON.stringify(imgs)
 				},
 				function(data){
 					console.log(typeof(data));
 					if(validator.form()){
 						if(data == "1"){
 							alert("上传成功");
 						}else{
 							alert("上传失败");
 						}
 					}				
 				},
 				"json"
 		 );
     } 
});
//上传成品帘商品
$("#byBtn").click(function(){
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil2 form");
	console.log(form.serialize());
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
		console.log(str);
		console.log(compositions);
	}
		
	var sampleImg = $("#sampleImg>img").attr("src");
	//console.log(sampleImg);
	var makeImg = $("#makeImg>img").attr("src");
	//console.log(makeImg);
	var str1 = form.serialize();
	console.log(str1);
	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	var imgs = {};
	imgs.mainImg = sampleImg;
	
	imgs.makeImg = makeImg;
	imgs.assistImg = detailsImg;
	console.log(imgs);
	str1=decodeURIComponent(str1,true);
	
	
	str1 = updateString(str1);
	console.log(JSON.stringify(imgs));
	/*表单提交*/
	var validator = $("#sampleT1").validate({
        rules : {
            // 对应表单元素的name属性
            "serialnumber" : {required:true,number:true},
            "price" : {required:true,number:true},
            "shading" : {required:true,number:true},
        },
        messages : {
            "serialnumber" : {required:'请输入型号'},
            "shading" : {required:'请输入遮光率'},
            "price" : {required:'请输入价格'},
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     
     if($("#addGoodsDeatil2 form").serialize()){
    	 console.log("1");
    	 $.post(
 				"http://192.168.0.90:8080/bukeManage/shoppingmall/updategoodsubmit.do",
 				{
 					sample:str1,
 					compositions:JSON.stringify(compositions),
 					imgs:JSON.stringify(imgs)
 				},
 				function(data){
 					console.log(typeof(data));
 					if(validator.form()){
 						if(data == "1"){
 							alert("上传成功");
 						}else{
 							alert("上传失败");
 						}
 					}				
 				},
 				"json"
 		 );
     } 
});
//上传配件商品
$("#pjBtn").click(function(){
	//获取组成 JSON.stringify
	var form = $("#addGoodsDeatil3 form");
	//console.log(form.serialize());
	var compositions = new Array();
	for(var i=1;i<form.length;i++){
		var aa = form.eq(i);
		var str = aa.serialize();
		str = decodeURIComponent(str,true);
		str = updateString(str);
		compositions[i-1]=JSON.parse(str);
		console.log(str);
		console.log(compositions);
	}
		
	var sampleImg = $("#sampleImg>img").attr("src");
	//console.log(sampleImg);
	var makeImg = $("#makeImg>img").attr("src");
	//console.log(makeImg);
	var str1 = form.serialize();
	console.log(str1);
	
	//获取详情图片 
	var detailsImg = new Array();
	var imgs = $("div[name='tupianDiv'] img");
	var j=0;
	for(var i=0;i<imgs.length;i++){
		if(imgs[i].name!="cuoPng"){
			detailsImg[j] = $(imgs[i]).attr("src");
			j++;
		}
	}
	var imgs = {};
	imgs.mainImg = sampleImg;
	
	imgs.makeImg = makeImg;
	imgs.assistImg = detailsImg;
	console.log(imgs);
	str1=decodeURIComponent(str1,true);
	
	
	str1 = updateString(str1);
	console.log(JSON.stringify(imgs));
	/*表单提交*/
	var validator = $("#sampleT2").validate({
        rules : {
            // 对应表单元素的name属性
            "serialnumber" : {required:true},
            "holePeice" : {required:true,number:true},
            "shading" : {required:true,number:true},
        },
        messages : {
            "serialnumber" : {required:'请输入型号'},
            "shading" : {required:'请输入遮光率'},
            "holePeice" : {required:'请输入价格'},
        },
        errorElement : "span",
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
     })
     
     if($("#addGoodsDeatil2 form").serialize()){
    	 //console.log("1");
    	 $.post(
 				"http://192.168.0.90:8080/bukeManage/shoppingmall/updategoodsubmit.do",
 				{
 					sample:str1,
 					compositions:JSON.stringify(compositions),
 					imgs:JSON.stringify(imgs)
 				},
 				function(data){
 					console.log(typeof(data));
 					if(validator.form()){
 						if(data == "1"){
 							alert("上传成功");
 						}else{
 							alert("上传失败");
 						}
 					}				
 				},
 				"json"
 		 );
     }
	
	 
});

